package com.company.cloud.crm.client;

import com.company.cloud.common.asserts.ValidatorUtils;
import com.company.cloud.common.bean.BaseClientResult;
import com.company.cloud.crm.modules.api.request.CustomerNumStatisticsRequest;
import com.company.cloud.crm.modules.api.response.CustomerNumStatisticsResponse;
import com.company.cloud.crm.modules.data.service.CustomerDataStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import com.company.cloud.crm.modules.api.request.Contact2UserAddRequest;
import com.company.cloud.crm.modules.api.response.Contact2UserAddResponse;
import com.company.cloud.crm.modules.api.service.CrmRemoteService;
import com.company.cloud.crm.modules.base.entity.CustomerContactInfo;
import com.company.cloud.crm.modules.mgr.service.CustomerContactMgrService;

import cn.hutool.core.bean.BeanUtil;

@RestController
@Service
public class CrmRemoteServiceImpl implements CrmRemoteService{
	
	@Autowired
	private CustomerContactMgrService customerContactMgrService;
	@Autowired
	private CustomerDataStatisticsService customerDataStatisticsService;

	@Override
	public BaseClientResult<Contact2UserAddResponse> addContact2User(Contact2UserAddRequest params) {
		try {
			ValidatorUtils.validate(params);
			CustomerContactInfo customerContact= customerContactMgrService.addCustomerContact(params.getCustUserId(), params.getUserId(), params.getIp());
			if(customerContact!=null){
				Contact2UserAddResponse data=new Contact2UserAddResponse();
				BeanUtil.copyProperties(customerContact, data);
				return BaseClientResult.success(data);
			}
			return BaseClientResult.success();
		} catch (Exception e) {
			return BaseClientResult.error(e);
		}
	}

	@Override
	public BaseClientResult<CustomerNumStatisticsResponse> customerNumStatistics(CustomerNumStatisticsRequest params) {
		try {
			ValidatorUtils.validate(params);
			int num= customerDataStatisticsService.customerNumStatistics(params.getUserId());
			return BaseClientResult.success(new CustomerNumStatisticsResponse(num));
		} catch (Exception e) {
			return BaseClientResult.error(e);
		}
	}

}
